define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope,Starbusiness_pushinfo,GoPage,GoDialog,$timeout) {
		
		//加载数据
		$scope.status=0;
		$scope.init_data = function(val) {
			$scope.status = val;
			Starbusiness_pushinfo.getvideolist($scope.status,1,function(data) {
				$scope.info = data.info;
				console.log(data)
			});
		}
		$scope.init_data(1); //必须在定义之后

		//跳转到编辑页面
		$scope.onshow_pushinfo_apply = function(id){
			GoPage.go_states("starbusiness_pushinfo_apply",{"id":id});
		}
		//删除
        $scope.del = function(id,index) {
            Starbusiness_pushinfo.del_info(id, function(data) {
                if(data.success) {
                	$scope.info.splice(index,1);
                    GoDialog.toast("删除成功！");
                } else {
                    GoDialog.toast(data.msg);
                }
            });
        }
        
        //下拉刷新
        $scope.input = new Object();
        $scope.input.nPage = 1;
        $scope.isLoad = false; //可以加载
        //下拉刷新 判断哪个模块进行刷新
        $scope.doRefresh = function() {
            //防止重复加载
            $scope.isLoad = true;
            Starbusiness_pushinfo.getvideolist($scope.status,1,function(data)   {
                    if(data != null) {
                     	$scope.info = data.info;
                    } else{
                    	$scope.info = new Object();
                    }
                    $scope.input.nPage = 1;
                },
                function() {
                    $scope.$broadcast('scroll.refreshComplete');
                    $timeout(function() {
                        $scope.isLoad = false;
                    }, 1500);
                });
        };
        //加载更多
        $scope.doRefreshMore = function() {
            //防止重复加载
            $scope.isLoad = true;
             Starbusiness_pushinfo.getvideolist($scope.status,$scope.input.nPage + 1,function(data)  {
                    if(data != null) {
                        if($scope.info != undefined) {
                            $scope.info = $scope.info.concat(data.info);
                            $scope.input.nPage += 1;
                        } else {
                            $$scope.info = data.info;
                        }
                    }
                },
                function() {
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                    $timeout(function() {
                        $scope.isLoad = false;
                    }, 1500);
                });
        };
        

	}

	controller.$inject = ['$scope', 'Starbusiness_pushinfo','GoPage','GoDialog','$timeout'];

	return app.registerController("starbusiness_pushinfoctrl",controller);
});